package 练习题;

//键盘录入一个三位数，计算其各位数字之和

import java.util.Scanner;

public class test04 {
    public static void main(String[] args) {
        while (true) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个三位数");
            int shu = sc.nextInt();
            int ge = 0;
            int shi = 0;
            int bai = 0;
            int num = 0;
            if (shu >= 100 && shu < 1000) {
                ge = shu % 10;
                shi = shu / 10 % 10;
                bai = shu / 100 % 10;

            } else {
                System.out.println("输入数字错误");
            }
            num = ge + shi + bai;
            System.out.println("各位数字之和为:" + num);
        }
    }
}
